import type {
  SearchBaseSelectors,
  SearchPageSelectors,
} from '../../../../module/page_enhancer/appearance/style_enhancement/platforms'
import { AppStyleCollections } from '../../../../types/constants'

/**
 * 页面类型
 */
export enum SoPageType {
  IndexSearch = 'index-search',
  IndexVideo = 'index-video',
  IndexEncyclopedia = 'index-encyclopedia',
  IndexWenku = 'index-wenku',
  Encyclopedia = 'encyclopedia',
  Wenku = 'wenku',
  Video = 'video',
  News = 'news',
  Web = 'web',
  NotFound = 'not-found',
  WenkuNotFound = 'wenku-not-found',
  Undefined = 'undefined',
  // 暂不支持
  IndexAi = 'index-ai',
  Ai = 'ai',
  GoodDoctor = 'good-doctor',
  Photo = 'photo',
  Qa = 'qa',
}

/**
 * 页面类型属性
 */
export interface SoPageTypeResult {
  type: SoPageType | 'default'
}

// ====================================================== 基础配置 ======================================================
// 搜索框容器
export const SO_SEARCH_BOX_SELECTOR: string = '#header #head .ac_wrap'
// 搜索结果项
export const SO_SEARCH_RESULT_CONTAINER_SELECTOR: string = '#warper #main .result'
// 广告结果项
export const SO_SEARCH_AD_RESULT_CONTAINER_SELECTOR: string = '#warper #main #m-spread-left'

// 基础选择器
export const SO_SEARCH_BASE_SELECTORS: SearchBaseSelectors = {
  searchBox: {
    input: '#header #head input#keyword',
    dropdown: {
      wrapper: SO_SEARCH_BOX_SELECTOR,
      menu: `${SO_SEARCH_BOX_SELECTOR} .ac_menu`,
      suggestions: `${SO_SEARCH_BOX_SELECTOR}:has(.ac_menu[ac_word]:not([ac_word=""]))`,
      history: `${SO_SEARCH_BOX_SELECTOR}:has(.ac_menu[ac_word][ac_word=""])`,
      clearHistoryBtn: `${SO_SEARCH_BOX_SELECTOR} #clear_history`,
      clearHistoryText: '删除历史',
    },
  },
  result: {
    container: SO_SEARCH_RESULT_CONTAINER_SELECTOR,
    item: `${SO_SEARCH_RESULT_CONTAINER_SELECTOR} > .res-list`,
  },
  adResult: {
    container: SO_SEARCH_AD_RESULT_CONTAINER_SELECTOR,
    item: SO_SEARCH_AD_RESULT_CONTAINER_SELECTOR,
    itemTitle: `${SO_SEARCH_AD_RESULT_CONTAINER_SELECTOR} a.e_haosou_fw_bg_title`,
  },
  rightAside: {
    containerSelector: '#warper #side, #wrapper #side',
    dragTargetSelector: `.${AppStyleCollections.Drag.AREA}`,
    dragTargetStyle: ``,
    handleIconStyle: ``,
    position: 'left',
  },
}

// 页面选择器
export const SO_SEARCH_PAGE_SELECTORS: SearchPageSelectors = {
  [SoPageType.Web]: {
    ...SO_SEARCH_BASE_SELECTORS,
    result: {
      container: `${SO_SEARCH_BASE_SELECTORS.result.container}, ${SO_SEARCH_BASE_SELECTORS.adResult.container}`,
      item: `${SO_SEARCH_RESULT_CONTAINER_SELECTOR} > :is(.res-list, .res-recommend-tag-cover), ${SO_SEARCH_AD_RESULT_CONTAINER_SELECTOR}`,
    },
    rightAside: {
      ...SO_SEARCH_BASE_SELECTORS.rightAside,
      dragTargetStyle: `bottom: -10px; left: -32px;`,
    },
  },
  [SoPageType.IndexSearch]: {
    ...SO_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '.page-wrap #main #bd_search form #input-container input#input',
      form: '.page-wrap #main #bd_search form',
      dropdown: {
        wrapper: '',
        menu: ``,
        suggestions: `.page-wrap #main #bd_search form #input-container .ac_wrap .ac_menu > li:not(.local)`,
        history: `.page-wrap #main #bd_search form #input-container .ac_wrap .ac_menu > li.local`,
        clearHistoryBtn: '.page-wrap #main #bd_search form #input-container .ac_wrap #clear_history',
        clearHistoryText: '删除历史',
      },
    },
    result: {
      container: `#main #card_container .hot-news-card ul`,
      item: `#main #card_container .hot-news-card ul > li`,
    },
  },
  [SoPageType.Video]: {
    ...SO_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '#app .so-header__content .so-header__left input.so-search__input',
      form: '#app .so-header__content .so-header__left .so-search__form',
      dropdown: {
        wrapper: '#app .so-header__content .so-header__left .so-suggest',
        menu: ``,
        suggestions: `#app .so-header__content .so-header__left .so-suggest .so-suggest__item.suggest`,
        history: `#app .so-header__content .so-header__left .so-suggest .so-suggest__item.history`,
        clearHistoryBtn: '#app .so-header__content .so-header__left .so-suggest .so-suggest__clear-history',
        clearHistoryText: '删除历史',
      },
    },
    result: {
      container: `#app .v-list`,
      item: `#app .v-list > li.v-list-item`,
    },
  },
  [SoPageType.News]: {
    ...SO_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '#head .so-header__content .so-header__left input.so-search__input',
      form: '#head .so-header__content .so-header__left .so-search__form',
      dropdown: {
        wrapper: '',
        menu: ``,
        hotRank: `#head .so-header__content .so-header__left .so-suggest .so-suggest__item.link`,
        suggestions: `#head .so-header__content .so-header__left .so-suggest .so-suggest__item.suggest`,
        history: `#head .so-header__content .so-header__left .so-suggest .so-suggest__item.history`,
        clearHistoryBtn: '#head .so-header__content .so-header__left .so-suggest .so-suggest__item.history .so-suggest__del',
        clearHistoryText: '删除',
      },
    },
    result: {
      container: `#wrapper #container #news`,
      item: `#wrapper #container #news > li`,
    },
    rightAside: {
      ...SO_SEARCH_BASE_SELECTORS.rightAside,
      dragTargetSelector: '.mh-hotnew-cont h2',
      handleIconStyle: `left: -24px !important;`,
    },
  },
  [SoPageType.Encyclopedia]: {
    ...SO_SEARCH_BASE_SELECTORS,
    result: {
      container: `#container .main .result`,
      item: `#container .main .result > li`,
    },
    rightAside: {
      ...SO_SEARCH_BASE_SELECTORS.rightAside,
      containerSelector: '#container .aside',
      dragTargetStyle: `bottom: -18px; left: -32px;`,
    },
  },
  [SoPageType.Wenku]: {
    ...SO_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '#app .so-header__content .so-header__left input.so-search__input',
      form: '#app .so-header__content .so-header__left .so-search__form',
      dropdown: {
        wrapper: '',
        menu: ``,
        suggestions: `#app .so-header__content .so-header__left .so-suggest .so-suggest__item.suggest`,
        history: `#app .so-header__content .so-header__left .so-suggest .so-suggest__item.history`,
        clearHistoryBtn: '#app .so-header__content .so-header__left .so-suggest .so-suggest__clear-history',
        clearHistoryText: '清除历史',
      },
    },
    result: {
      container: `#app .wenku-search__main .wenku-search__resList, #app .wenku-search__main #fengwu-ads > ul`,
      item: `#app .wenku-search__main .wenku-search__resList > li, #app .wenku-search__main #fengwu-ads > ul > li`,
    },
    adResult: {
      container: '#app .wenku-search__main #fengwu-ads > ul',
      item: '#app .wenku-search__main #fengwu-ads > ul > li',
      itemTitle: `#app .wenku-search__main #fengwu-ads > ul > li a.e_haosou_fw_bg_title`,
    },
  },
  [SoPageType.IndexVideo]: {
    ...SO_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '#app .so-search .so-search__form input.so-search__input',
      form: '#app .so-search .so-search__form',
      dropdown: {
        wrapper: '',
        menu: ``,
        suggestions: `#app .so-search .so-search__form .so-suggest .so-suggest__item.suggest`,
        history: `#app .so-search .so-search__form .so-suggest .so-suggest__item.history`,
        clearHistoryBtn: '#app .so-search .so-search__form .so-suggest .so-suggest__clear-history',
        clearHistoryText: '删除历史',
      },
    },
  },
  [SoPageType.IndexWenku]: {
    ...SO_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '#app #wenku-index__inputBox__content__search form input',
      form: '#app #wenku-index__inputBox__content__search form',
      dropdown: {
        wrapper: '',
        menu: ``,
        suggestions: `#app #wenku-index__inputBox__content__search .wenku-index__queryList .wenku-index__queryList__list__item`,
        history: `#app #wenku-index__inputBox__content__search .wenku-index__queryList .wenku-index__queryList__list__logItem`,
        clearHistoryBtn: '#app #wenku-index__inputBox__content__search .wenku-index__queryList .wenku-index__queryList__list__logItem .wenku-index__queryList__list__logItem__delete',
        clearHistoryText: '删除',
      },
    },
  },
}
